/**
 *
 * @author DnD Binary Source
 */
package Entities;

import AbstractClasses.Lista;
import java.io.Serializable;
import java.util.ArrayList;

public class SourceList extends Lista implements Serializable{
        private static SourceList sourceList;
    
    private SourceList(){
        elements = new ArrayList<Object>();
        sourceList = this;
    }
    
    public static SourceList getInstance(){
        return sourceList;
    }
        
    @Override
    public void add(Object source){
        initializeList();
        if(source instanceof Source){
            this.elements.add((Source) source);
            Handler.updateSource();
        }
        else{
             throw new UnsupportedOperationException("You can add only books here.");
        }
    }
    
    @Override
    public void remove(int position){
        this.elements.remove(position);
        Handler.updateSource();
    }
    
    @Override
    public void updateItem(){
        Handler.updateSource();
    }
    
    public void initializeList(){
        if(elements==null){
            this.elements = new ArrayList<Object>();
        }
    }
}
